home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Screen Loc197025172001.psc / MHotkey.bas < prev    next >
Encoding:
BASIC Source File  |  2001-02-28  |  1.7 KB  |  56 lines

  1. Attribute VB_Name = "MHotkey"
  2. Private Const MOD_ALT = &H1
  3. Private Const MOD_CONTROL = &H2
  4. Private Const MOD_SHIFT = &H4
  5. Private Const PM_REMOVE = &H1
  6. Private Const WM_HOTKEY = &H312
  7.  
  8. Private Type POINTAPI
  9.     x As Long
  10.     y As Long
  11. End Type
  12.  
  13. Private Type Msg
  14.     hWnd As Long
  15.     Message As Long
  16.     wParam As Long
  17.     lParam As Long
  18.     time As Long
  19.     pt As POINTAPI
  20. End Type
  21.  
  22. Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
  23. Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
  24. Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
  25. Private Declare Function WaitMessage Lib "user32" () As Long
  26. Private bCancel As Boolean
  27. Private Sub ProcessMessages()
  28.     Dim Message As Msg
  29.     'loop until bCancel is set to True
  30.     Do While Not bCancel
  31.         'wait for a message
  32.         WaitMessage
  33.         'check if it's a HOTKEY-message
  34.         If PeekMessage(Message, Parent.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
  35.             If cWave.Cancel = True Then WaterStart
  36.         End If
  37.         'let the operating system process other events
  38.         DoEvents
  39.     Loop
  40. End Sub
  41. Public Sub RegHotkey()
  42.     bCancel = False
  43.     
  44.     'register the Ctrl-Alt-End hotkey
  45.     RegisterHotKey Parent.hWnd, &HBFFF&, MOD_CONTROL Or MOD_ALT, vbKeyEnd
  46.     
  47.     'process the Hotkey messages
  48.     ProcessMessages
  49. End Sub
  50.  
  51. Public Sub unRegHotkey()
  52.     bCancel = True
  53.     'unregister hotkey
  54.     Call UnregisterHotKey(Parent.hWnd, &HBFFF&)
  55. End Sub
  56.